<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>产品信息查询</title>
<link href="__PUBLIC__/plugins/bootstrap.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-dashen.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/font-awesome.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/animate.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
{include file="common/header" /}
	<div class="col-md-9 wow fadeInLeft">
		<ul class="breadcrumb">
  			<li><a href="__PUBLIC__/index.php">首页</a></li>
  			<li><a href="{:url('ProductInfo/frontlist')}">产品信息信息列表</a></li>
  			<li class="active">查询结果显示</li>
  			<a class="pull-right" href="{:url('ProductInfo/frontAdd')}" style="display:none;">添加产品信息</a>
		</ul>
		<div class="row">
			<?php
				/*计算起始序号*/
				$startIndex = ($currentPage-1) * $rows;
				$currentIndex = $startIndex+1;
				/*遍历记录*/
			?>
			{volist name="productInfoRs" id="productInfo" key="i"}
			<?php
				$clearLeft = "";
				if(($i-1)%4 == 0) $clearLeft = "style=\"clear:left;\"";
			?>
			<div class="col-md-3 bottom15" {$clearLeft}>
			  <a  href="{:url('ProductInfo/frontshow',array('productNo'=>$productInfo['productNo']))}"><img class="img-responsive" src="__PUBLIC__/{$productInfo.productPhoto}" /></a>
			     <div class="showFields">
			     	<div class="field">
	            		产品编号:{$productInfo.productNo}
			     	</div>
			     	<div class="field">
	            		产品类别:{$productInfo.productClassF.productClassName}
			     	</div>
			     	<div class="field">
	            		产品名称:{$productInfo.productName}
			     	</div>
			     	<div class="field">
	            		产品单价:{$productInfo.price}
			     	</div>
			     	<div class="field">
	            		产品库存:{$productInfo.leftCount}
			     	</div>
			     	<div class="field">
	            		生产日期:{$productInfo.madeDate}
			     	</div>
			        <a class="btn btn-primary top5" href="{:url('ProductInfo/frontshow',array('productNo'=>$productInfo['productNo']))}">详情</a>
			        <a class="btn btn-primary top5" onclick="productInfoEdit('{$productInfo.productNo}');" style="display:none;">修改</a>
			        <a class="btn btn-primary top5" onclick="productInfoDelete('{$productInfo.productNo}');" style="display:none;">删除</a>
			     </div>
			</div>
			{/volist}

			<div class="row">
				<div class="col-md-12">
					<nav class="pull-left">
						<ul class="pagination">
							<li><a href="#" onclick="GoToPage({$currentPage-1},{$totalPage});" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
							<?php
								$startPage = $currentPage - 5;
								$endPage = $currentPage + 5;
								if($startPage < 1) $startPage=1;
								if($endPage > $totalPage) $endPage = $totalPage;
								for($i=$startPage;$i<=$endPage;$i++) {
							?>
							<li class="<?php echo $currentPage==$i?"active":""; ?>"><a href="#"  onclick="GoToPage({$i},{$totalPage});">{$i}</a></li>
							<?php } ?>
							<li><a href="#" onclick="GoToPage({$currentPage+1},{$totalPage});"><span aria-hidden="true">&raquo;</span></a></li>
						</ul>
					</nav>
					<div class="pull-right" style="line-height:75px;" >共有{$recordNumber}条记录，当前第 {$currentPage}/{$totalPage}  页</div>
				</div>
			</div>
		</div>
	</div>

	<div class="col-md-3 wow fadeInRight">
		<div class="page-header">
    		<h1>产品信息查询</h1>
		</div>
		<form name="productInfoQueryForm" id="productInfoQueryForm" action="{:url('ProductInfo/frontlist')}" class="mar_t15" method="post">
			<div class="form-group">
				<label for="productNo">产品编号:</label>
				<input type="text" id="productNo" name="productNo" value="{$productNo}" class="form-control" placeholder="请输入产品编号">
			</div>
            <div class="form-group">
            	<label for="productClass_productClassId">产品类别：</label>
                <select id="productClass_productClassId" name="productClass_productClassId" class="form-control">
                	<option value="0">不限制</option>
	 				<?php
	 				foreach($productClassList as $productClass) {
	 					$selected = "";
 					if($productClass['productClassId'] == $productClass['productClassId'])
 						$selected = "selected";
	 				?>
 				 <option value="{$productClass.productClassId}" {$selected}>{$productClass.productClassName}</option>
	 				<?php
	 				}
	 				?>
 			</select>
            </div>
			<div class="form-group">
				<label for="productName">产品名称:</label>
				<input type="text" id="productName" name="productName" value="{$productName}" class="form-control" placeholder="请输入产品名称">
			</div>
            <input type=hidden name=currentPage id="currentPage" value="{$currentPage}" />
            <button type="submit" class="btn btn-primary" onclick="$('#currentPage').val(1);return true;">查询</button>
        </form>
	</div>

		</div>
</div>
<div id="productInfoEditDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" style="width:900px;" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><i class="fa fa-edit"></i>&nbsp;产品信息信息编辑</h4>
      </div>
      <div class="modal-body" style="height:450px; overflow: scroll;">
      	<form class="form-horizontal" name="productInfoEditForm" id="productInfoEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		  <div class="form-group">
			 <label for="productInfo_productNo_edit" class="col-md-3 text-right">产品编号:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="productInfo_productNo_edit" name="productInfo.productNo" class="form-control" placeholder="请输入产品编号" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="productInfo_productClass_productClassId_edit" class="col-md-3 text-right">产品类别:</label>
		  	 <div class="col-md-9">
			    <select id="productInfo_productClass_productClassId_edit" name="productInfo_productClass_productClassId" class="form-control">
			    </select>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_productName_edit" class="col-md-3 text-right">产品名称:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="productInfo_productName_edit" name="productInfo_productName" class="form-control" placeholder="请输入产品名称">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_price_edit" class="col-md-3 text-right">产品单价:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="productInfo_price_edit" name="productInfo_price" class="form-control" placeholder="请输入产品单价">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_leftCount_edit" class="col-md-3 text-right">产品库存:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="productInfo_leftCount_edit" name="productInfo_leftCount" class="form-control" placeholder="请输入产品库存">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_madeDate_edit" class="col-md-3 text-right">生产日期:</label>
		  	 <div class="col-md-9">
                <div class="input-group date productInfo_madeDate_edit col-md-12" data-link-field="productInfo_madeDate_edit" data-link-format="yyyy-mm-dd">
                    <input class="form-control" id="productInfo_madeDate_edit" name="productInfo_madeDate" size="16" type="text" value="" placeholder="请选择生产日期" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_productPhoto_edit" class="col-md-3 text-right">产品图片:</label>
		  	 <div class="col-md-9">
			    <img  class="img-responsive" id="productInfo_productPhotoImg" border="0px"/><br/>
			    <input type="hidden" id="productInfo_productPhoto_edit" name="productInfo_productPhoto"/>
			    <input id="productPhotoFile" name="productPhotoFile" type="file" size="50" />
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="productInfo_productDesc_edit" class="col-md-3 text-right">产品描述:</label>
		  	 <div class="col-md-9">
			 	<textarea name="productInfo_productDesc" id="productInfo_productDesc_edit" style="width:100%;height:500px;"></textarea>
			 </div>
		  </div>
		</form> 
	    <style>#productInfoEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
      <div class="modal-footer"> 
      	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      	<button type="button" class="btn btn-primary" onclick="ajaxProductInfoModify();">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{include file="common/footer" /}
<script src="__PUBLIC__/plugins/jquery.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrap.js"></script>
<script src="__PUBLIC__/plugins/wow.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrap-datetimepicker.min.js"></script>
<script src="__PUBLIC__/plugins/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jsdate.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
//实例化编辑器
var productInfo_productDesc_edit = UE.getEditor('productInfo_productDesc_edit'); //产品描述编辑器
/*跳转到查询结果的某页*/
function GoToPage(currentPage,totalPage) {
    if(currentPage==0) return;
    if(currentPage>totalPage) return;
    document.productInfoQueryForm.currentPage.value = currentPage;
    document.productInfoQueryForm.submit();
}

/*可以直接跳转到某页*/
function changepage(totalPage)
{
    var pageValue=document.productInfoQueryForm.pageValue.value;
    if(pageValue>totalPage) {
        alert('你输入的页码超出了总页数!');
        return ;
    }
    document.productInfoQueryForm.currentPage.value = pageValue;
    documentproductInfoQueryForm.submit();
}

/*弹出修改产品信息界面并初始化数据*/
function productInfoEdit(productNo) {
	$.ajax({
		url :  "{:url('ProductInfo/update')}?productNo=" + productNo ,
		type : "get",
		dataType: "json",
		success : function (productInfo, response, status) {
			if (productInfo) {
				$("#productInfo_productNo_edit").val(productInfo.productNo);
				$.ajax({
					url: "{:url('ProductClass/listAll')}",
					type: "get",
					dataType: "json",
					success: function(productClasss,response,status) { 
						$("#productInfo_productClass_productClassId_edit").empty();
						var html="";
		        		$(productClasss).each(function(i,productClass){
		        			html += "<option value='" + productClass.productClassId + "'>" + productClass.productClassName + "</option>";
		        		});
		        		$("#productInfo_productClass_productClassId_edit").html(html);
		        		$("#productInfo_productClass_productClassId_edit").val(productInfo.productClass);
					}
				});
				$("#productInfo_productName_edit").val(productInfo.productName);
				$("#productInfo_price_edit").val(productInfo.price);
				$("#productInfo_leftCount_edit").val(productInfo.leftCount);
				$("#productInfo_madeDate_edit").val(productInfo.madeDate);
				$("#productInfo_productPhoto_edit").val(productInfo.productPhoto);
				$("#productInfo_productPhotoImg").attr("src", "__PUBLIC__/" + productInfo.productPhoto);
				productInfo_productDesc_edit.setContent(productInfo.productDesc, false);
				$('#productInfoEditDialog').modal('show');
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*删除产品信息信息*/
function productInfoDelete(productNo) {
	if(confirm("确认删除这个记录")) {
		$.ajax({
			type : "POST",
			url: "{:url('ProductInfo/deletes')}",
			data : {
				productNos : productNo,
			},
			dataType: "json",
			success : function (obj) {
				if (obj.success) {
					alert("删除成功");
					$("#productInfoQueryForm").submit();
					//location.href= "{:url('ProductInfo/frontlist')}";
				}
				else 
					alert(obj.message);
			},
		});
	}
}

/*ajax方式提交产品信息信息表单给服务器端修改*/
function ajaxProductInfoModify() {
	$.ajax({
		url :  "{:url('ProductInfo/update')}",
		type : "post",
		dataType: "json",
		data: new FormData($("#productInfoEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                $("#productInfoQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();

    /*生产日期组件*/
    $('.productInfo_madeDate_edit').datetimepicker({
    	language:  'zh-CN',  //语言
    	format: 'yyyy-mm-dd',
    	minView: 2,
    	weekStart: 1,
    	todayBtn:  1,
    	autoclose: 1,
    	minuteStep: 1,
    	todayHighlight: 1,
    	startView: 2,
    	forceParse: 0
    });
})
</script>
</body>
</html>

